package com.example.thread.base.demo2;



import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/12/8 18:20
 */
@Slf4j
public class TaskDemo {
    public static void main(String[] args) throws Exception {
        //futureTaskTest();

        String text = " xx，";
        log.info("result:{}",isContainChinese(text));
    }

    private static void futureTaskTest() throws Exception {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                System.out.println("休息5S 再干活");
                Thread.sleep(5 * 1000);
                return 2;
            }
        };
        FutureTask<Integer> task = new FutureTask<>(callable);
        Thread thread = new Thread(task);
        thread.run();
        System.out.println(" 我在干活...");
        Integer result = task.get();
        System.out.println("拿到的结果为：" + result);
    }


    /**
     * 字符串是否包含中文
     *
     * @param str 待校验字符串
     * @return true 包含中文字符 false 不包含中文字符
     * @throws Exception
     */
    public static final String chinessRegex = "[\u4E00-\u9FA5|\\！|\\，|\\。|\\（|\\）|\\《|\\》|\\“|\\”|\\？|\\：|\\；|\\【|\\】]";
    private static final Pattern chinesePattern = Pattern.compile(chinessRegex);

    public static boolean isContainChinese(String str) {
        if (StringUtils.isEmpty(str)) {
            return false;
        }
        Matcher m = chinesePattern.matcher(str);
        if (m.find()) {
            return true;
        }
        return false;
    }
}
